//
//  XFNewFeatureCell.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/13.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFNewFeatureCell.h"
#import "Masonry.h"

@interface XFNewFeatureCell ()
@property(nonatomic, weak) UIImageView *bgView;
@property(nonatomic, weak) UIButton *startBtn;
@end

@implementation XFNewFeatureCell

- (instancetype)initWithFrame:(CGRect)frame {

  if (self = [super initWithFrame:frame]) {
    [self setupUI];
  }
  return self;
}

- (void)setIndex:(NSInteger)index {

  _index = index;

  if (_index == kImageCount - 1) {
    self.startBtn.hidden = NO;
    [self startAnimation];
  } else {
    self.startBtn.hidden = YES;
  }
  NSString *imageName =
      [NSString stringWithFormat:@"new_feature_%ld", _index + 1];
  self.bgView.image = [UIImage imageNamed:imageName];
}

- (void)startAnimation {

  self.startBtn.transform = CGAffineTransformMakeScale(0, 0);

  [UIView animateWithDuration:1
      animations:^{
        //

        self.startBtn.transform = CGAffineTransformIdentity;
      }
      completion:^(BOOL finished){
          //

      }];
}

- (void)startBtnDidClick {

  [[NSNotificationCenter defaultCenter]
      postNotificationName:@"selectViewcontroller"
                    object:nil];
}

- (void)setupUI {
  UIImageView *bgView = [[UIImageView alloc] init];
  [self.contentView addSubview:bgView];
  self.bgView = bgView;

  UIButton *startBtn =
      [[UIButton alloc] initWithTitle:@"开始体验"
                                Color:nil
                               BgIcon:@"new_feature_finish_button"
                                Image:nil];

  [self.contentView addSubview:startBtn];
  self.startBtn = startBtn;

  //添加点击时间
  [self.startBtn addTarget:self
                    action:@selector(startBtnDidClick)
          forControlEvents:UIControlEventTouchUpInside];

  //布局
  [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.contentView.mas_left);
    make.right.equalTo(self.contentView.mas_right);
    make.top.equalTo(self.contentView.mas_top);
    make.bottom.equalTo(self.contentView.mas_bottom);
  }];

  [self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(self.mas_centerX);
    make.bottom.equalTo(self.mas_bottom).offset(-200);
  }];
}

@end
